
package configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

@Configuration
@EnableWebMvc
@ComponentScan("bean")
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		registry.addViewController("/schedule").setViewName("/schedule");
		registry.addViewController("/mainUI").setViewName("/mainUI");
		registry.addViewController("/register").setViewName("/register");
		registry.addViewController("/carousel").setViewName("/carousel");
		registry.addViewController("/upload").setViewName("/upload");
		
		registry.addViewController("/photoView").setViewName("/photoView");
		registry.addViewController("/showPlane").setViewName("/showPlane");
		registry.addViewController("/show3D").setViewName("/show3D");
		registry.addViewController("/500").setViewName("/500");
	}

	// 配置静态资源处理
	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
		configurer.enable();
	}

	@Bean
	public InternalResourceViewResolver viewResolver() {
		// 配置JSP视图解析
		InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
		viewResolver.setPrefix("/jsp");
		viewResolver.setSuffix(".jsp");
		viewResolver.setViewClass(JstlView.class);
		viewResolver.setExposeContextBeansAsAttributes(true);
		return viewResolver;
	}

}
